<?php

namespace Admin\Controller;

class UploadController extends MainController {

    public function goods_more() {//商品批量图片提交
        $id = I("get.id");
        $is_pic = 0; //是否图片
        //判断是否在允许文件类型
        $path = C("tempFile");
        $upload = new \Think\Upload(); // 实例化上传类
        $upload->maxSize = C('upload_max_size'); // 设置附件上传大小
//        $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->rootPath = $path; // 设置附件上传目录
        $upload->saveName = array('uniqid', '');
        $upload->autoSub = false;
        $info = $upload->upload();
        $uploadInfo = $info['file'];
        $type = strtolower(substr(strrchr($uploadInfo['name'], '.'), 1)); //文件类型
        $savename = $uploadInfo['savename']; //数据库保存名
        if ($info) {
            if (in_array($type, explode(",", C("picTypes")))) {
                
                $image = new \Think\Image();
                $image->open($path . $savename);
                $image->thumb(150, 150, \Think\Image::IMAGE_THUMB_FIXED)->save($path . "150_" . $savename);
//                 $image->open($path . $savename);
//                 $image->thumb(270, 200, \Think\Image::IMAGE_THUMB_SCALE)->save($path . "270_" . $savename); 
                $is_pic = 1;
                $data['pid'] = $id;
                $data['pic'] = $savename;
//                $data['uid'] = session("shop_id");
              $max =  M("pics")->where("pid = ".$id."")->max("ord");
                $data['ord'] = $max+1;
               $latsid = M("pics")->add($data);
//            echo M("pics")->getlastsql();
            }
            
        } else {
            $arr['error'] = $upload->getError();
            echo json_encode($arr);
            exit;
        }
        
        $arr = array(
            'name' => $savename,
            'pic' => C("SITE_URL") . "/" . $path . "150_" . $savename,
            'state' => 1,
            'is_pic' => $is_pic,
            'id' => $latsid
        );
        echo json_encode($arr);
        exit;
    }

}

?>